//
//  GWStatuseOriginalView.m
//  新浪微博
//
//  Created by qianfeng on 16/2/18.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWStatuseOriginalView.h"
#import "GWOriginalStatuseFrame.h"
#import "GWStatuseModel.h"
#import "UIImageView+WebCache.h"
#import "GWStatusePhotosView.h"
#import "GWStatuseLabel.h"
@interface GWStatuseOriginalView()
/**昵称*/
@property (nonatomic,weak)UILabel *nameLabel;
/**正文*/
@property (nonatomic,weak)GWStatuseLabel *textLabel;
/**来源*/
@property (nonatomic,weak)UILabel *sourceLabel;
/**时间*/
@property (nonatomic,weak)UILabel *timeLabel;
/**头像*/
@property (nonatomic,weak)UIImageView *iconView;
/**相册*/
@property (nonatomic,weak)GWStatusePhotosView *photosView;

@property (nonatomic,weak)UIImageView *vipView;
@end
@implementation GWStatuseOriginalView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        self.userInteractionEnabled =YES;
        //昵称
        UILabel *namelabel =[[UILabel alloc]init];
        [self addSubview:namelabel];
        self.nameLabel =namelabel;
        namelabel.font =OriginalStatuseNameFont;
        
        //正文
        GWStatuseLabel *textLabel =[[GWStatuseLabel alloc]init];
        [self addSubview:textLabel];
        self.textLabel =textLabel;
        //时间
        UILabel *timeLabel =[[UILabel alloc]init];
        [self addSubview:timeLabel];
        self.timeLabel =timeLabel;
        timeLabel.font =OriginalStatuseTimeFont;
        timeLabel.textColor =[UIColor orangeColor];
        //来源
        UILabel *sourceLabel =[[UILabel alloc]init];
        [self addSubview:sourceLabel];
        self.sourceLabel =sourceLabel;
        sourceLabel.font =OriginalStatuseSourceFont;
        sourceLabel.textColor =[UIColor lightGrayColor];
        //头像
        UIImageView *iconView =[[UIImageView alloc]init];
        [self addSubview:iconView];
        self.iconView =iconView;
        
        //会员图标
        UIImageView *vipView =[[UIImageView alloc]init];
        [self addSubview:vipView];
        self.vipView =vipView;
        vipView.contentMode =UIViewContentModeCenter;
        
        //相册
        GWStatusePhotosView *photosView =[[GWStatusePhotosView alloc]init];
        [self addSubview:photosView];
        self.photosView =photosView;
        
    }
    return self;
}

-(void)setOriginalStatuseFrame:(GWOriginalStatuseFrame *)originalStatuseFrame
{
    _originalStatuseFrame =originalStatuseFrame;
    GWStatuseModel *statuse =originalStatuseFrame.statuse;
    
    self.frame =originalStatuseFrame.frame;
    
    self.nameLabel.frame =originalStatuseFrame.nameLabelF;
    self.nameLabel.text =statuse.user.name;
    
    if (statuse.user.isVip) {
        self.nameLabel.textColor =[UIColor orangeColor];
        self.vipView.hidden=NO;
        
        self.vipView.image =[UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%d",statuse.user.mbrank]];
        self.vipView.frame =originalStatuseFrame.vipViewF;
    }
    else
    {
        self.nameLabel.textColor =[UIColor blackColor];
        self.vipView.hidden=YES;
    }
    
    self.timeLabel.frame =originalStatuseFrame.timeLabelF;
    self.timeLabel.text =statuse.created_at;
    self.timeLabel.width =[statuse.created_at boundingRectWithSize:CGSizeMake(200, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:OriginalStatuseTimeFont} context:nil].size.width;
    
    self.sourceLabel.frame =originalStatuseFrame.sourceLabelF;
    self.sourceLabel.text =statuse.source;
    self.sourceLabel.x =CGRectGetMaxX(self.timeLabel.frame)+HomeStatuseCellInset*0.5;
    
    self.textLabel.frame =originalStatuseFrame.textLabelF;
    self.textLabel.attributedString =statuse.attributedText;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:statuse.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"compose_pic_add"]];
    self.iconView.frame =originalStatuseFrame.iconViewF;
    
    
    if (statuse.pic_urls.count) {
        self.photosView.hidden =NO;
        self.photosView.frame =originalStatuseFrame.photosViewF;
        self.photosView.pic_urls =originalStatuseFrame.statuse.pic_urls;
    }
    else
    {
        self.photosView.hidden =YES;
    }
}
@end
